package com.test.utils;

import java.util.Random;
import java.util.stream.IntStream;

/**
 * @author ssang
 * @date 2021-12-09 14:06
 */
public class SaltUtil {
    private static final String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    public static String getRandomSalt(int num){
        StringBuffer salt = new StringBuffer();
        IntStream.range(0,num).forEach(i->{
            Random random = new Random();
            //获取随机下标
            int index = random.nextInt(str.length()+1);
            //获取字符
            char result = str.charAt(index);
            salt.append(result);
        });
        return salt.toString();
    }
}
